package edu.tsinghua.ddb.components;

import java.rmi.RemoteException;
import java.util.Map;
import java.util.Map.Entry;

import com.sun.rowset.CachedRowSetImpl;

import edu.tsinghua.ddb.beans.Sqlet;
import edu.tsinghua.ddb.data.LocalDataAccess;
import edu.tsinghua.ddb.site.Site;
import edu.tsinghua.ddb.site.SiteImp;

public class Dispatcher {
	

	public CachedRowSetImpl queryAll(Map<Site, Sqlet> works){
		for(Entry<Site,Sqlet> entry : works.entrySet()){
			try {
				if(entry.getKey() instanceof SiteImp){
					CachedRowSetImpl rs = LocalDataAccess.query(entry.getValue().getRawSQL());
					return rs;
				}else{
					CachedRowSetImpl rs = entry.getKey().query(entry.getValue().getRawSQL());
					return rs;
				}
			} catch (RemoteException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return null;
	}
}
